package me;

import java.io.Serializable;
import java.util.Objects;

/**
 * @author yexy
 * @date 2020/6/15 9:19 上午
 * @description
 */
public class Student implements Serializable {
    static final long serialVersionUID = -3387516993124229948L;

    public Student(){

    }

    public Student(String no, String name, Integer age) {
        this.no = no;
        this.name = name;
        this.age = age;
    }

    private String no;
    private String name;
    private Integer age;

    public String getNo() {
        return no;
    }

    public void setNo(String no) throws NumberFormatException,StuNoException {
        int i = Integer.parseInt(no);
        if (i < 0)
            throw new StuNoException("学好输入错误");
        this.no = no;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) throws AgeException{
        if (age <=0 || age > 150)
            throw new AgeException("年龄需要在0-150之间");

        this.age = age;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return Objects.equals(no, student.no);
    }

    @Override
    public String toString() {
        return
                "学号：" + no +
                ", 姓名：" + name +
                ", 年龄：" + age;
    }
}
